<?php

require_once('classes/Facilities.php');

$id = (int)$_REQUEST['id'];

if (empty($id)) {
	throw new Exception('No ID supplied');
}

$filedir = sprintf("facilities/%d", $id);

$facilities = new Facilities("$filedir/facility.tsv");

foreach($facilities->get_all() as $facility) {

	if (isset($_FILES['picture'])) {
		$facility->add_uploaded_picture($_FILES['picture']);
		header(sprintf('Location: ./?id=%d', $facility->ID));
		die;
	}
	echo isset($_REQUEST['popup']) ? $facility->popup_html() : $facility->full_html();
}
